package everything.search;

public class SearchAgentState implements Comparable<SearchAgentState>{
	private int _x;
	private int _y;
	private String _orientation;
	private int _xSentry;
	private int _ySentry;
	private String _dSentry;
	private boolean _health;
	private boolean[] _flags;

	// constructor
	public SearchAgentState(int x, int y, String orientation,int xSentry, int ySentry, String dSentry, boolean health, boolean[] flags){
		this._health = health;
		this._dSentry = dSentry;
		this._xSentry = xSentry;
		this._ySentry = ySentry;
		this._orientation = orientation;
		this._x = x;
		this._y = y;
		this._flags = flags;
	}

	/*public SearchAgentState(String direction, SearchAgentState state) {






		if (direction.compareToIgnoreCase("north") == 0){

		}
		else if (direction.compareToIgnoreCase("south") == 0){

		}
		else  if (direction.compareToIgnoreCase("west") == 0){

		}
		else  if (direction.compareToIgnoreCase("east") == 0){

		}
	}
	 */
	public int getX() {
		return _x;
	}
	public int getY() {
		return _y;
	}
	public String getOrientation() {
		return _orientation;
	}

	/**
	 *
	 * @returns Direction of sentry
	 */
	public String getDSentry() {
		return _dSentry;
	}
	public int getXSentry() {
		return _xSentry;
	}
	public int getYSentry() {
		return _ySentry;
	}

	public boolean getHealth() {
		return _health;
	}

	@Override
	public String toString(){
		return "Position: ["+_x+","+_y+"] Slide: <"+_orientation+"> Sentry: ["+_xSentry+","+_ySentry+"] -<"+_dSentry+"> " + (_health ?  "Alive" : "Dead");
	}

	public boolean[] getFlags() {
		return _flags;
	}
	@Override
	public boolean equals(Object o){
		System.out.println("Sup56");
		if (o instanceof SearchAgentState){
			SearchAgentState other = (SearchAgentState)o;
			System.out.println(this + "  -  " + other);
			if (this._x != other._x) return false;
			if (this._y != other._y) return false;
			if (this._xSentry != other._xSentry) return false;
			if (this._ySentry != other._ySentry) return false;
			if (this._dSentry != null && other._dSentry != null){ 
				if(!this._dSentry.equals(other._dSentry)) return false;
			} else if (other._dSentry != null){ 
				return false;
			} else if (this._dSentry != null) {
				return false;
			}
			if (this._orientation != null && other._orientation !=null){ 
				if(!this._orientation.equals(other._orientation)) return false;
			} else if (other._orientation != null ){ 
				return false;
			} else if (this._orientation != null){
				return false;
			}
			if (this._health != other._health) return false;
			for (int i=0; i<this._flags.length; i++){
				if (this._flags[i] != other._flags[i]) return false;
			}
			return true;
		} else return false;

	}

//	@Override
	public int compareTo(SearchAgentState other) {
		if (this._x > other._x) return -1;
		else if (this._x < other._x) return 1; 
		if (this._y > other._y) return 1;
		if (this._y < other._y) return -1;
		if (this._xSentry > other._xSentry) return 1;
		if (this._xSentry < other._xSentry) return -1;
		if (this._ySentry > other._ySentry) return 1;
		if (this._ySentry < other._ySentry) return -1;
		if (this._dSentry != null && other._dSentry !=null){
			int tmp = this._dSentry.compareTo(other._dSentry);
			if (tmp!=0) return tmp;
		} else if (other._dSentry!=null){
			return -1;
		} else if (this._dSentry!=null){
			return 1;
		}
		if (this._orientation != null && other._orientation != null){
				int tmp = this._orientation.compareTo(other._orientation);
				if (tmp!=0) return tmp;
		} else if (other._orientation!=null){
			return -1;
		} else if (this._orientation!=null){
			return 1;
		}
		if (this._health){
			if (!other._health) return -1;
		} else if (other._health) return 1;
		for (int i=0; i<this._flags.length; i++){
			if (this._flags[i]){
				if (!other._flags[i]) return -1;
			} else if (other._flags[i]) return 1;
		}
		return 0;
	}

}